<template>
	<view class="warp">
		<!-- #ifdef APP-PLUS -->
		<view class="title-contents"><view class="top-view status"></view></view>
		<!-- #endif -->
		<view class="login-title">
			<view class="logo"><image src="/static/images/common/logo.png" mode=""></image></view>
		</view>
		<!-- 验证码码登录 -->
		<view class="login-phone form-wapper">
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-shouji"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" 
				name="username" v-model="username" type="number" placeholder="请输入手机号" /></view>
			</view>
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-yanzhengma"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" name="vercode" v-model="vercode" type="number"  placeholder="请输入验证码" /></view>

				<view >
					<button type="default" @click="getSendSms()">获取验证码</button>
				</view>
			</view>
		</view>

		<button type="primary" class="login-btn" @click="getCode_login()">登录</button>

	</view>
</template>
<script>
export default {
		data() {
			return {
			   username:'username',
			   vercode:'vercode',
			   urls:'https://4de16698-d9f4-443a-b416-ef1037cce952.bspapp.com/http'
			}
		},
		methods:{
			getCode_login(){
				uni.request({
					url:this.urls+'/user/code_login',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					data:{
						username:this.username,
						vercode:this.vercode,
					},
					success: res =>{
						if(res.data.code == 0){
							//登陆成功
							uni.showToast({
								title:'登录成功',
								duration:2000
							})
							//存放本地
							uni.setStorage({
								key: 'token',
								data: res.data.token
							})
							//两秒后返回
							setTimeout(v=>{
								uni.reLaunch({
									url:'/pages/user/user'
								})
							},2000)
						}else if (this.username.length ==0) {
							uni.showToast({
								title:'用户名不能为空',
								icon: 'none',
								duration: 2000
							})
						}else{
							uni.showToast({
							title: res.data.errMsg,
							icon: 'none',
							duration: 2000	
							})
						}
					},
					fail: err => {
						console.log(err);
					}
				})
			},
			getSendSms() {
				uni.$u.http.post('/user/sendSms',{
					mobile: this.username,
						type: 'login'
				}).then(res=>{
					console.log(res.data)
				})
			}
		},
	}
</script>
<style lang="scss">
@import  "login.scss"
</style>
